package com.zhuss.meeting.processor;

import com.zhuss.bean.bo.meeting.apply.DeleteApplyBo;
import com.zhuss.bean.vo.meeting.apply.DetailApplyVo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.meeting.db.dao.ext.MeetingApplyDao;
import com.zhuss.meeting.db.entity.MeetingRoomApply;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhushanshuo
 * @Date: 2020/2/23 13:19
 */
@Component("applyDelete")
public class ApplyDelete extends AbstractProcessor<Object, DeleteApplyBo> implements Processor<Object, DeleteApplyBo> {

    @Autowired
    private MeetingApplyDao meetingApplyDao;

    @Autowired
    @Qualifier("applyRead")
    private ApplyRead applyRead;

    @Override
    public Object process(DeleteApplyBo deleteApplyBo) throws WpsException {
        Long applyId = deleteApplyBo.getApplyId();
        String name = ((DetailApplyVo) applyRead.detail(applyId)).getRoomName();
        MeetingRoomApply m = new MeetingRoomApply();
        m.setApplyId(deleteApplyBo.getApplyId());
        m.setDeleted(deleteApplyBo.getDeleted());

        m.setModifierId(deleteApplyBo.getConcurrentUserId());
        m.setModifier(deleteApplyBo.getConcurrentUserName());
        m.setModifyTime(new Date());
        meetingApplyDao.delete(m);
        deleteApplyBo.setName(name);
        return null;
    }

    @Override
    public Object log(DeleteApplyBo param) throws WpsException {
        OpLog record = new OpLog();
        record.setMoudle(MoudleEnum.会务.key());
        record.setAction(LogActionEnum.会议室申请删除.key());
        record.setTargetId(param.getApplyId());
        record.setTargetName(param.getName());
        record.setContent("参数: " + JsonUtil.toJson(param));
        record.setReason(param.getExceptionReason());

        record.setCreatorId(param.getConcurrentUserId());
        record.setCreator(param.getConcurrentUserName());
        record.setCreateTime(new Date());
        log(record);
        return null;
    }

    @Override
    public void check(DeleteApplyBo deleteApplyBo) throws WpsException {

    }
}
